package com.tg.demo.web;

import com.tg.demo.common.ConstantUtil;
import com.tg.demo.common.Result;
import com.tg.demo.entity.User;
import com.tg.demo.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * ManagerController
 *
 * @author yuanjin
 * @date 2019/4/15
 */
@Controller
@Slf4j
@RequestMapping("/manager")
public class ManagerController {

    @Resource
    private UserService userService;

    @RequestMapping(value = "/department")
    @ResponseBody
    public Result getDepartment(User user) {
        Result result = new Result(ConstantUtil.FAILURE_CODE, ConstantUtil.FAILURE_MESSAGE);
        if (user != null) {
            List<String> list = userService.getDepartments();
            result = new Result(ConstantUtil.SUCCESS_CODE, ConstantUtil.SUCCESS_MESSAGE);
            result.setData(list);
        }
        return result;
    }

    @RequestMapping(value = "/professional")
    @ResponseBody
    public Result getProfessionals(User user) {
        Result result = new Result(ConstantUtil.FAILURE_CODE, ConstantUtil.FAILURE_MESSAGE);
        if (user != null) {
            List<String> list = userService.getProfessionals(user);
            result = new Result(ConstantUtil.SUCCESS_CODE, ConstantUtil.SUCCESS_MESSAGE);
            result.setData(list);
        }
        return result;
    }

    @RequestMapping(value = "/classRoom")
    @ResponseBody
    public Result getClassRooms(User user) {
        Result result = new Result(ConstantUtil.FAILURE_CODE, ConstantUtil.FAILURE_MESSAGE);
        if (user != null) {
            List<String> list = userService.getClassRooms(user);
            result = new Result(ConstantUtil.SUCCESS_CODE, ConstantUtil.SUCCESS_MESSAGE);
            result.setData(list);
        }
        return result;
    }
}
